package net.colorlotus7;

import java.util.Scanner;

import static net.colorlotus7.Constants.*;

/**
 * @Description:
 * @Author: Jason.zhu
 * @Create: 2020/02/19 11:54
 */

public class NioClient {
    private static NioClientHandle nioClientHandle;

    public static void start(){
        if(nioClientHandle != null){
            nioClientHandle.stop();
        }
        nioClientHandle = new NioClientHandle(DEFAULT_SERVER_IP, DEFAULT_PORT);
        new Thread(nioClientHandle, "Client").start();
    }

    public static boolean sendMsg(String msg) throws Exception{
        nioClientHandle.sendMsg(msg);
        return true;
    }

    public static void main(String[] args) throws Exception {
        start();
        Scanner scanner = new Scanner(System.in);
        while (NioClient.sendMsg(scanner.next()));
    }

}
